<template>
  <div class="conant">
    <el-card class="box-card" style="margin-top: 20px">
      <div style="display: flex; justify-content: space-between">
        <div>
          <!-- <el-icon>
            <Search />
          </el-icon> -->
          <p>筛选搜索</p>
        </div>
        <el-form label-width="140px" class="searchFrom">
          <!-- 1 -->
          <el-form-item label="输入搜索：">
            <el-input type="text" placeholder="服务单号" v-model="id" style="width: 203px"></el-input>
          </el-form-item>
          <!-- 2 -->
          <el-form-item label="处理状态：">
            <el-select v-model="select" placeholder="全部" style="width: 203px">
              <el-option label="待处理" value="1" />
              <el-option label="退货中" value="2" />
              <el-option label="已完成" value="3" />
              <el-option label="已拒绝" value="4" />
            </el-select>
          </el-form-item>
          <!-- 3 -->
          <el-form-item label="申请时间：" class="time1">
            <el-date-picker v-model="time" type="date" placeholder="请选择时间" style="width: 203px" />
          </el-form-item>
          <!-- 4 -->
          <el-form-item label="操作人员：">
            <el-input type="text" placeholder="全部" v-model="operator" style="width: 203px"></el-input>
          </el-form-item>
          <!-- 5 -->
          <el-form-item label="处理时间：" class="time2">
            <el-date-picker v-model="process" type="date" placeholder="请选择时间" style="width: 203px" />
          </el-form-item>
        </el-form>
      </div>
    </el-card>
  </div>

  <!-- 卡片2 -->
  <el-card class="btn_out">
    <div style="display: flex; align-items: center">
      <el-icon>
        <Tickets />
      </el-icon>
      <p>数据列表</p>
    </div>
  </el-card>

  <!-- 数据的展示 -->
  <el-table row-key="id" :data="tableData" style="width: 100%" @selection-change="handleSelectionChange" :border="true">
    <!-- 多选框 -->
    <el-table-column type="selection" fixed select-on-indeterminate width="60">
    </el-table-column>
    <el-table-column prop="id" label="服务单号" />
    <el-table-column prop="createTime" label="申请时间" width="200">
      <template #default="scope">
        <div>
          {{
            scope.row.createTime
            ? dayjs(scope.row.createTime).format("YYYY-MM-DD HH:mm:ss")
            : ""
          }}
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="memberUsername" label="用户账号" />
    <el-table-column prop="productRealPrice" label="退款金额" width="180" />
    <el-table-column prop="status" label="申请状态" width="180" />
    <el-table-column prop="handleTime" label="处理时间" width="200">
      <template #default="scope">
        <div>
          {{
            scope.row.handleTime
            ? dayjs(scope.row.handleTime).format("YYYY-MM-DD HH:mm:ss")
            : ""
          }}
        </div>
      </template>
    </el-table-column>
    <el-table-column fixed="right" label="操作" width="150" flex="right">
      <template #default="scope">
        <el-button @click="onApply(scope.row.id)">查看详情</el-button>
      </template>
    </el-table-column>
  </el-table>

  <div class="bottom f">
    <!-- 批量删除 -->
    <el-form-item class="delete">
      <el-select v-model="deleteall" placeholder="全部">
        <el-option label="批量删除" value="1" />
      </el-select>
      <el-button style="margin-left: 15px" type="primary" @click="onDelete">确定</el-button>
    </el-form-item>

    <!-- 分页器 -->
    <el-pagination class="pagination" v-model:current-page="pagination.pageNum" v-model:page-size="pagination.pageSize"
      background :page-sizes="[5, 10, 15]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" />
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRoute } from "vue-router";
import { Tickets, Search } from "@element-plus/icons-vue";
import type { Ref } from "vue";
import * as api from "../../request/api";
import useTable from "../../hooks/useTables";
import dayjs from "dayjs";
import type { IAdminListItem } from "../../request/QmsAdminConreiller/index";
import { ElMessage, ElMessageBox } from "element-plus";
import { ElTable } from "element-plus";
import router from "../../router";

//表格数据
let {
  tableData,
  getTableData,
  pagination,
  // handleSizeChange,
  // handleCurrentChange,
} = useTable(api.returnApply.returnApplyList);

//输入框绑定值
let id = ref(); //服务单号
const select = ref(""); //处理状态
const time = ref(""); //申请时间
const operator = ref(""); //操作人员
const process = ref(""); //处理时间
const deleteall = ref("1"); //批量删除

//分页
const handleSizeChange = (val: number) => {
  getTableData();
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val: number) => {
  getTableData();
  console.log(`current page: ${val}`);
};

//查询搜索请求
let onSearch = async () => {
  // console.log(id.value);
  getTableData();
  let listData = await api.returnApply.returnApplyList({
    id: id.value,
    status: select.value,
    createTime: time.value,
    handleMan: operator.value,
    handleTime: process.value,
    pageNum: 1,
    pageSize: 5,
  });
  // 注意：tableData在高阶函数中是ref声明
  tableData.value = listData;
};
//重置
let onClear = () => {
  id.value = "";
  time.value = "";
  process.value = "";
  operator.value = "";
  select.value = "";
};
//select
interface User {
  date: string;
  name: string;
  address: string;
}
const multipleSelection = ref<User[]>([]);
const handleSelectionChange = (val: User[]) => {
  multipleSelection.value = val;
  console.log(multipleSelection.value);
};
//确定删除
let onDelete = () => {
  console.log(multipleSelection.value);
  if (multipleSelection.value.length == 0) {
    ElMessage({
      message: "请选择要操作的申请",
      type: "warning",
      duration: 1000,
    });
    return;
  }
  ElMessageBox.confirm("是否要进行删除操作?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      // // 确定删除
      // // 遍历所得到的ids数组
      // multipleSelection.value.forEach(async (item) => {
      //   await api.reason.getreturnReasonlistdel(item);
      //   getTableData();
      // });
      ElMessage({
        type: "success",
        message: "删除成功",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "取消删除",
      });
    });
  // 注意：tableData在高阶函数中是ref声明
  tableData.value.splice(multipleSelection, 1);
};

// 弹框
let visible = ref(false);

// 编辑 查看详情
let onApply = (data: any) => {
  console.log(data);
  router.push({ path: "/oms/returnApplyDetail", query: { id: data } });
};

getTableData();
</script>

<style lang="scss" scoped>
.searchFrom {
  display: flex;
  justify-content: start;
  flex-wrap: wrap;
}

.bottom {
  width: 100%;
  display: flex;
  justify-content: space-between;
}

.delete {
  margin-top: 30px;
}

.pagination {
  margin-top: 15px;
}

.el-table--fit {
  border-bottom: 1px solid #ebeef5;
}

.search {
  height: 100vh;
}

:deep .el-table thead {
  font-weight: bold !important;
}

:deep .el-scrollbar__view {
  width: 100% !important;
}

:deep .el-table .el-table__cell {
  text-align: center !important;
}

.el-form--inline .el-form-item {
  margin-right: 10px;
}

.el-form-item__label {
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  box-sizing: border-box;
}

.el-form-item--mini.el-form-item,
.el-form-item--small.el-form-item {
  margin-bottom: 18px;
}

.el-form--inline .el-form-item__label {
  float: none;
  display: inline-block;
}

.el-form-item__label {
  line-height: 32px;
}

.el-card.is-always-shadow {
  box-shadow: none;
  width: 100%;
}

.search_container {
  left: 0;
  right: 0;
  padding: 10px 35px 15px 0;
  width: 100%;
}

.breadcrumb {
  height: 45px;
  border-bottom: 1px solid #ebeef5;
  font-size: 20px;
}

.search {
  padding: 20px 15px 20px 5px;
  background-color: #fff;
  margin-bottom: 20px;

  .search_top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
  }
}

// .btn {
//   background-color: #fff;
//   display: flex;
//   justify-content: space-between;
// }

.btn_out {
  margin-bottom: 20px;
}

el-card {
  :deep .el-input {
    width: 200px !important;
  }
}

:deep .el-button {
  font-size: 12px !important;
}

.conant {
  margin-top: 60px;
  margin-bottom: 20px;
}
</style>
